#ifndef SMOOTHWINDOWSIDEANIMATION_H
#define SMOOTHWINDOWSIDEANIMATION_H

#include <windows.h>
#include <WindowsX.h>
#include <map>

class SmoothWindowSideAnimation;

#include "Utilities.h"
#include "WindowEdge.h"

using namespace std;


class SmoothWindowSideAnimation
{
public:
	typedef void (*WNDSIDEANIMATIONVALUECHANGEDPROC)(SmoothWindowSideAnimation* sender, int step, int currentValue, LPVOID tag);
	typedef void (*WNDSIDEANIMATIONPROC)(SmoothWindowSideAnimation* sender, LPVOID tag);

	SmoothWindowSideAnimation(HWND hWnd, LPVOID tag);
	~SmoothWindowSideAnimation();
	
	HWND GetHWnd();
	bool IsRunning();
	bool StartAnimation(int speed, int windowEdgeStartValue, int amount, WindowEdge windowEdge);
	bool CancelAnimation();

	void AnimationStarted(WNDSIDEANIMATIONPROC ptr);
	void AnimationCancelled(WNDSIDEANIMATIONPROC ptr);
	void AnimationFinished(WNDSIDEANIMATIONPROC ptr);
	void ValueChanged(WNDSIDEANIMATIONVALUECHANGEDPROC ptr);
private:
	int speed;
	int amount;
	int counter;
	int windowEdgeStartValue;
	int windowEdgeCurrentValue;
	int timerId;

	bool increment;
	bool timerEnabled;

	WindowEdge windowEdge;
	HWND hWnd;
	LPVOID tag;

	WNDSIDEANIMATIONPROC onAnimationStartedPtr;
	WNDSIDEANIMATIONPROC onAnimationCancelledPtr;
	WNDSIDEANIMATIONPROC onAnimationFinishedPtr;
	WNDSIDEANIMATIONVALUECHANGEDPROC onValueChangedPtr;


	int Round(double x);
	void StartTimer();
	void StopTimer();	
	void Animate();
	void CallWndSideAnimationEvent(WNDSIDEANIMATIONPROC ptr);
	void CallWndSideValueChangedEvent(WNDSIDEANIMATIONVALUECHANGEDPROC ptr, int step, int currentValue);


	static map<int, SmoothWindowSideAnimation*> instances;
	static int instanceCounter;

	static VOID CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
};

#endif